package com.smart.campus.web.controller.school;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.smart.campus.common.annotation.Log;
import com.smart.campus.common.enums.BusinessType;
import com.smart.campus.school.domain.CalzzCommittee;
import com.smart.campus.school.service.ICalzzCommitteeService;
import com.smart.campus.common.core.controller.BaseController;
import com.smart.campus.common.core.domain.AjaxResult;
import com.smart.campus.common.utils.poi.ExcelUtil;
import com.smart.campus.common.core.page.TableDataInfo;

/**
 * 班委组成，包含课代等信息Controller
 * 
 * @author Zhihe.Li
 * @date 2021-06-27
 */
@Controller
@RequestMapping("/school/committee")
public class CalzzCommitteeController extends BaseController
{
    private String prefix = "school/committee";

    @Autowired
    private ICalzzCommitteeService calzzCommitteeService;

    @GetMapping()
    public String committee(Long classId, ModelMap mmap)
    {
        mmap.put("clazzId",classId);
        return prefix + "/committee";
    }

    /**
     * 查询班委组成，包含课代等信息列表
     */
//    @RequiresPermissions("school:committee:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CalzzCommittee calzzCommittee)
    {
        startPage();
        List<CalzzCommittee> list = calzzCommitteeService.selectCalzzCommitteeList(calzzCommittee);
        return getDataTable(list);
    }

    /**
     * 导出班委组成，包含课代等信息列表
     */
//    @RequiresPermissions("school:committee:export")
    @Log(title = "班委组成，包含课代等信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CalzzCommittee calzzCommittee)
    {
        List<CalzzCommittee> list = calzzCommitteeService.selectCalzzCommitteeList(calzzCommittee);
        ExcelUtil<CalzzCommittee> util = new ExcelUtil<CalzzCommittee>(CalzzCommittee.class);
        return util.exportExcel(list, "committee");
    }

    /**
     * 新增班委组成，包含课代等信息
     */
    @GetMapping("/add")
    public String add(Long classId, ModelMap mmap)
    {
        mmap.put("clazzId",classId);
        return prefix + "/add";
    }

    /**
     * 新增保存班委组成，包含课代等信息
     */
//    @RequiresPermissions("school:committee:add")
    @Log(title = "班委组成，包含课代等信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CalzzCommittee calzzCommittee)
    {
        return toAjax(calzzCommitteeService.insertCalzzCommittee(calzzCommittee));
    }

    /**
     * 修改班委组成，包含课代等信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CalzzCommittee calzzCommittee = calzzCommitteeService.selectCalzzCommitteeById(id);
        mmap.put("calzzCommittee", calzzCommittee);
        return prefix + "/edit";
    }

    /**
     * 修改保存班委组成，包含课代等信息
     */
//    @RequiresPermissions("school:committee:edit")
    @Log(title = "班委组成，包含课代等信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CalzzCommittee calzzCommittee)
    {
        return toAjax(calzzCommitteeService.updateCalzzCommittee(calzzCommittee));
    }

    /**
     * 删除班委组成，包含课代等信息
     */
//    @RequiresPermissions("school:committee:remove")
    @Log(title = "班委组成，包含课代等信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(calzzCommitteeService.deleteCalzzCommitteeByIds(ids));
    }
}
